package com.probiz.estore.core.security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
/**
 * 功能：将doAction参数移到queryString的首参数位置
 *
 */
public class ProbizHttpServletRequestWrapper extends HttpServletRequestWrapper {
	private String paramName;   
	public ProbizHttpServletRequestWrapper(HttpServletRequest request) {
		super(request);
	}

	public ProbizHttpServletRequestWrapper(HttpServletRequest request, String paramName) {
		super(request);
		this.paramName=paramName;
	}

	public String getQueryString(){
		if(paramName==null)
			return super.getQueryString();
		String qs = super.getQueryString();
		String da = super.getParameter(paramName);
		if(qs==null||!qs.startsWith(paramName)){
			if(da!=null){
				int ix = qs==null?0:qs.indexOf(paramName);
				//?a=b&doAction=kk&c
				if(qs!=null&&ix>0){
					//paramName位置错误,将paramName调整到第一个参数
					return qs.substring(ix)+"&"+qs.substring(0,ix-1);
				}
				return (qs==null?"":qs+"&")+paramName+"="+da;
			}
		}
		return qs;
	}
}
